From b3c6c3055fb7bcc8511f9bb5abf9483807399e18 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Mon, 16 Jul 2018 23:37:45 +0200 Subject: [PATCH] babl: simplify babl_format_with_space Rely on any format string containing the substring "-space" that this substring is the marker for the end of the encoding part of the format name - which is what we want replicated in our new format with a different color space. --- babl/babl-format.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/babl/babl-format.c b/babl/babl-format.c index e426feb..d295165 100644 --- a/babl/babl-format.c +++ b/babl/babl-format.c @@ -719,31 +719,21 @@ babl_format_with_space (const char *name, const Babl *space) if (BABL_IS_BABL (example_format)) { - if (babl_format_get_space (example_format) == babl_space ("sRGB")) - { - name = babl_get_name (example_format); // the safest choice when getting sRGB based formats to cast - } - else + name = babl_get_name (example_format); + if (babl_format_get_space (example_format) != babl_space ("sRGB")) { + strcpy (&tmpname[0], name); + + if (strstr (tmpname, "-space")) + *strstr (tmpname, "-space") = '\0'; + name = &tmpname[0]; - if (example_format->format.components == babl_format_get_model (example_format)->model.components && - (strstr (name, "CIE") || strstr (name, "cairo"))) - { - // use the model name directly, for now CIE and cairo should catch most such issues - strcat (&tmpname[0], babl_get_name (babl_format_get_model (example_format))); - } - else - { - int i; - for (i = 0; i < example_format->format.components;i ++) - strcat (&tmpname[0], babl_get_name ((void*)example_format->format.component[i])); - } - strcat (&tmpname[0], " "); - strcat (&tmpname[0], babl_get_name ((void*)example_format->format.type[0])); } } - if (!space) space = babl_space ("sRGB"); + if (!space) + space = babl_space ("sRGB"); + if (space->class_type == BABL_FORMAT) { space = space->format.space; -- 2.30.2